package com.wqtz.chechai.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.Toast;

import com.wqtz.chechai.R;
import com.wqtz.chechai.base.lvbaseadapter.LvBaseAdapter;
import com.wqtz.chechai.base.lvbaseadapter.ViewHolder;
import com.wqtz.chechai.bean.LoanDetailInfoBean;
import com.wqtz.chechai.view.activities.ApprovalInfoActivity;
import com.yinglan.swiperefresh.SwipeMenu;
import com.yinglan.swiperefresh.SwipeMenuListView;

import java.util.ArrayList;
import java.util.List;

/**
 * 项目名称： CheChai
 * 创建人 :  Kisum
 * 创建时间: 2017/2/21
 */

public class LoanDetailInfoAdapter extends LvBaseAdapter<LoanDetailInfoBean> implements SwipeMenuListView.OnMenuItemClickListener {
    private List<LoanDetailInfoBean> mDatas = new ArrayList<>();
    /**
     * 2种状态：最新一期借款 过去借款
     */
    private final int THE_LATEST_PERIOD = 0;
    private final int OLD_PERIOD = 1;
    private Context mContext;

    public LoanDetailInfoAdapter(Context context, int resId) {
        super(resId);
        mContext = context;
    }

    @Override
    public void bindDatas(final List<LoanDetailInfoBean> list, final int position, ViewHolder holder) {
        mDatas.clear();
        mDatas.addAll(list);
        LoanDetailInfoBean loanDetailInfoBean = list.get(position);
        holder.setText(R.id.tv_period, "第" + loanDetailInfoBean.getLoanDetailPeriods() + "期");
        holder.setText(R.id.tv_loan_detail_info,loanDetailInfoBean.getLoanDetailInfo());
        holder.setText(R.id.tv_loan_time,loanDetailInfoBean.getLoanDetailTime());
        holder.setCirCleImag(R.id.iv_loaninfo_detail,R.mipmap.loan_detail_icon);
        switch (loanDetailInfoBean.getLoanDetailType()) {
            /**
             * 2种状态：最新一期借款 过去借款
             */
            case THE_LATEST_PERIOD:
                //最新一期借款
                holder.getView(R.id.tv_period).setBackgroundResource(R.mipmap.loan_detail_red_cicle);
                break;
            case OLD_PERIOD:
                //过去借款
                holder.getView(R.id.tv_period).setBackgroundResource(R.mipmap.loan_detail_gray_cicle);
                break;
        }
    }

    @Override
    public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
        switch (index) {
            case 0:
                Toast.makeText(mContext,"delete",Toast.LENGTH_SHORT).show();
                mDatas.remove(position);
                clearData();
                addData(mDatas);
                break;
            default:
                break;
        }
        return false;
    }

}
